import { selectUsers } from '../api/get/allUser'
import { selectCompanys } from '../api/get/allCompany'
import { selectBrowses } from '../api/get/allBrowse'
import { selectComments } from '../api/get/allComment'
import { selectDataContents } from '../api/get/allDataContent'
import { selectDataTypes } from '../api/get/allDataType'
import { selectESGCategorys } from '../api/get/allESGCategory'
import { selectESGMessages } from '../api/get/allESGMessage'
import { selectKeyWords } from '../api/get/allKeyWord'
import { selectSubscriptions } from '../api/get/allSubscription'
import { selectTags } from '../api/get/allTag'
import { selectIndex } from '../api/get/indexData'

import { addUser } from '../api/post/addUser'
import { deleteUser } from '../api/delete/deleteUser'
import { updateUser } from '../api/put/updateUser'
export const actions = {
    //1.获取分页全部用户
    async getAllUser(context) {
        let mapData = context.state.tableData
        // console.log(mapData.current, mapData.size, mapData.map)
        await selectUsers(mapData.current, mapData.size, mapData.map).then((res) => {
            console.log(res)
            context.commit('setTableData', res.data.data)
            context.commit('setKeys', Object.keys(res.data.data.list[0]))
        })
    },
    //2.获取分页全部浏览记录
    async getAllBrowse(context) {
        let mapData = context.state.tableData
        //console.log(mapData.current, mapData.size, mapData.map)
        await selectBrowses(mapData.current, mapData.size, mapData.map).then((res) => {
            console.log(res)
            context.commit('setTableData', res.data.data)
            context.commit('setKeys', Object.keys(res.data.data.list[0]))
        })
    },

    //3.获取分页全部评论
    async getAllComment(context) {
        let mapData = context.state.tableData
        // console.log(mapData.current, mapData.size, mapData.map)
        await selectComments(mapData.current, mapData.size, mapData.map).then((res) => {
            console.log(res)
            context.commit('setTableData', res.data.data)
            context.commit('setKeys', Object.keys(res.data.data.list[0]))
        })
    },

    //4.获取分页全部公司
    async getAllCompany(context) {
        let mapData = context.state.tableData
        // console.log(mapData.current, mapData.size, mapData.map)
        await selectCompanys(mapData.current, mapData.size, mapData.map).then((res) => {
            console.log(res)
            context.commit('setTableData', res.data.data)
            context.commit('setKeys', Object.keys(res.data.data.list[0]))
        })
    },

    //5.获取分页全部未分类数据
    async getAllDataContent(context) {
        let mapData = context.state.tableData
        //console.log(mapData.current, mapData.size, mapData.map)
        await selectDataContents(mapData.current, mapData.size, mapData.map).then((res) => {
            console.log(res)
            context.commit('setTableData', res.data.data)
            context.commit('setKeys', Object.keys(res.data.data.list[0]))
        })
    },

    //6.获取分页全部未分类数据类型
    async getAllDataType(context) {
        let mapData = context.state.tableData
        // console.log(mapData.current, mapData.size, mapData.map)
        await selectDataTypes(mapData.current, mapData.size, mapData.map).then((res) => {
            console.log(res)
            context.commit('setTableData', res.data.data)
            context.commit('setKeys', Object.keys(res.data.data.list[0]))
        })
    },

    //7.获取分页全部ESG分类类型
    async getAllESGCategory(context) {
        let mapData = context.state.tableData
        console.log(mapData.current, mapData.size, mapData.map)
        await selectESGCategorys(mapData.current, mapData.size, mapData.map).then((res) => {
            console.log(res)
            context.commit('setTableData', res.data.data)
            context.commit('setKeys', Object.keys(res.data.data.list[0]))
        })
    },


    //9.获取分页全部ESG分类数据
    async getAllESGMessage(context) {
        let mapData = context.state.tableData
        //console.log(mapData.current, mapData.size, mapData.map)
        await selectESGMessages(mapData.current, mapData.size, mapData.map).then((res) => {
            console.log(res)
            context.commit('setTableData', res.data.data)
            context.commit('setKeys', Object.keys(res.data.data.list[0]))
        })
    },

    //10.获取分页全部关键词
    async getAllKeyWord(context) {
        let mapData = context.state.tableData
        //console.log(mapData.current, mapData.size, mapData.map)
        await selectKeyWords(mapData.current, mapData.size, mapData.map).then((res) => {
            console.log(res)
            context.commit('setTableData', res.data.data)
            context.commit('setKeys', Object.keys(res.data.data.list[0]))
        })
    },

    //11.获取分页用户全部订阅记录
    async getAllSubscription(context) {
        let mapData = context.state.tableData
        //console.log(mapData.current, mapData.size, mapData.map)
        await selectSubscriptions(mapData.current, mapData.size, mapData.map).then((res) => {
            console.log(res)
            context.commit('setTableData', res.data.data)
            context.commit('setKeys', Object.keys(res.data.data.list[0]))
        })
    },

    //12.获取分页全部公司标签
    async getAllTag(context) {
        let mapData = context.state.tableData
        //console.log(mapData.current, mapData.size, mapData.map)
        await selectTags(mapData.current, mapData.size, mapData.map).then((res) => {
            console.log(res)
            context.commit('setTableData', res.data.data)
            context.commit('setKeys', Object.keys(res.data.data.list[0]))
        })
    },

    //13.获取首页数据
    async getIndex(context) {
        await selectIndex(context.state.user.id).then((res) => {
            console.log("index", res)
            context.commit('setIndexData', res.data.data)
        })
    },

    //用户的其他管理功能实现
    //14.增加用户
    async AddUser(context,from) {
        await addUser(from.contact,from.password,from.type,from.username).then((res) => {
            console.log("index", res)
            context.commit('setIndexData', res.data.data)
        })
    },

    //15.删除用户
    async DeleteUser(context,id) {
        await deleteUser(id).then((res) => {
            console.log("index", res)
            context.commit('setIndexData', res.data.data)
        })
    },

    //16.更新用户
    async UpdateUser(context,row) {
        await updateUser(row.id,row.account,row.contact,row.password,row.type,row.username,row.level).then((res) => {
            console.log("index", res)
            context.commit('setIndexData', res.data.data)
        })
    }, 





}